class TopLine extends React.Component {
    constructor(props) {
        super(props);
           
        this.state = {
            menuicon: !0,
            merchantName:this.props.merchantName||'',
            selindex: -1
        };
    }

    componentDidMount() {

    }

    navClick(url, i, e) {
        let { selindex } = this.state
        if (selindex == i) return
        this.setState({ selindex: i }, () => {
            this.formatlist()
            // window.location.href = `${url}.html`
        })
    }
    menuicon() {
        let { menuicon } = this.state
        this.setState({ menuicon: !menuicon })
    }
    quit() {
        $.cookie('token', "");
        window.location.href = './login.html'
    }

    render() {
        let { menuicon,merchantName } = this.state
        return (
            <div className='topLine'>
                <div  className="topLine_l">
                    {/* <img src="./src/ghlogo.png" alt="" />
                    <div className="name">工商银行</div> */}
                </div>
                <div className="topLine_m">
                  
                </div>

                <div className="topLine_r">
                    <p>{merchantName}</p>
                        <img onClick={this.quit} src="./src/quiticon.png" />

                    {/* <a className='quita' onClick={this.quit}>退出登录</a> */}
                    {/* <img src="./src/search.png" alt="" />
                    <span>新手指导</span>
                    <img src="./src/tz.png" alt="" />
                    <span className="username">也好</span>
                    <img src="./src/zh.png" alt="" /> */}
                </div>
            </div>
        )
    }
}

class LeftMenu extends React.Component {
    constructor(props) {
        super(props);
        console.log(props, 'props');

        this.state = {
            category: this.props.category,
            code: this.props.code,
            class: this.props.class,
            height: this.props.height,
            showcode: this.props.height,
            selone: this.props.selone,
            leftnavlist: [
                // {
                //      icon: "icon-dianpu-copy",
                //     name: "工资管理",
                //     showcode: "list",
                //     code: "list",
                //     mallmenu: [],
                // },
                // {
                //     icon: "icon-dianpu-copy",
                //     name: "参数设置",
                //     showcode: "settings",
                //     code: "settings",
                //     mallmenu: [],
                // },
                // {
                //     icon: "icon-dianpu-copy",
                //     name: "分类管理",
                //     showcode: "goodstype",
                //     code: "goodstype",
                //     mallmenu: [],
                // },
                
                {
                    icon: "icon-dianpu-copy",
                    name: "账号管理",
                    showcode: "account",
                    code: "account",
                    mallmenu: [],
                },
                {
                    icon: "icon-dianpu-copy",
                    name: "信息管理",
                    showcode: "list",
                    code: "list",
                    mallmenu: [],
                },
                {
                    icon: "icon-dianpu-copy",
                    name: "申请管理",
                    showcode: "apply",
                    code: "apply",
                    mallmenu: [],
                },
            ],
            leftnavhtml: [],
            pagearr: []
        };
    }


    componentDidMount() {
        let { height, leftnavlist } = this.state, leftnavhtml = [], showcode = ""
        showcode = height
        this.setState({ showcode: height })



        leftnavlist.forEach((x, i) => {
            let mallmenuhtml = []
            if (x.mallmenu.length > 0) {
                x.mallmenu.forEach(y => {
                    mallmenuhtml.push(
                        <div onClick={this.nav.bind(this, x.code)} className='rows'>
                            <div className={"twocategory "} >
                                <p style={{ marginLeft: "35" }}>{x.name}</p>
                            </div>
                        </div>
                    )
                })
                leftnavhtml.push(
                    <div className='rows' onClick={this.ischildshow.bind(this, x.showcode)}>
                        <div className={"category " + (`${this.state.showcode == x.showcode ? 'check' : ''}`)} >
                            <div className="disflexitems">
                                <img className="cash" src={`./src/info${this.state.showcode == x.showcode ?'_c':''}.png`}  />
                                <p>{x.name}</p>
                            </div>
                            <div className="categorymore">
                                <img src={`./src/${this.state.showcode == x.showcode ? "select_xl" : "select_xl01"}.png`} />
                            </div>
                        </div>
                    </div>
                )
                leftnavhtml.push(
                    <div className={`tagbox ${x.showcode + "navbox"}`}>
                        {mallmenuhtml}
                    </div>
                )
            } else {
                leftnavhtml.push(
                    <div className='rows'>
                        <div className={"category " + (`${this.state.code == x.code ? 'check' : ''}`)} onClick={this.nav.bind(this, x.code)} >
                            <div className="disflexitems">
                            <img className="cash" src={`./src/info${this.state.showcode == x.showcode ?'':'_c'}.png`} />  
                                <p>{x.name}</p>
                            </div>

                        </div>
                    </div>
                )
            }

        })


        this.setState({ leftnavhtml, })
    }
    nav(e) {
        var path = `${e}.html`;
        window.location.href = path;
    }
    ischildshow(i, e) {
        let { showcode } = this.state, that = this
        console.log(showcode, 'showcode');
        this.setState({ selone: i })
        if (showcode == e) {
            that.setState({ showcode: "" })
        } else {
            that.setState({ showcode: e })
        }
    }
    render() {
        return (
            <div className='LeftMenu'>
                {this.state.leftnavhtml}

               

            </div >



        )
    }
}